package fiveGame.Util;

import java.io.IOException;
import java.util.ArrayList;

import fiveGame.impl.ChessDao;

/** 

* @author Tiangle 

* @version 创建时间：2021年9月4日 下午2:46:26 

* 

*/
public class Control {
	ChessDao cd = new ChessDao();
	TiangleUtil t = new TiangleUtil();
	public void m() throws IOException, ClassNotFoundException {
		while(true) {
			System.out.println("****菜单****");
			System.out.println("1.开始游戏\n2.读取存档\n3.查看已完成游戏棋谱\n4.退出");
			switch(t.getInt(1, 4)) {
			case 1:
				start();
				break;
			case 2:
				
			case 3:
				ArrayList<String> as = cd.showOld();
				if(as==null) {
					System.out.println("没有棋谱！");
					break;
				}
				System.out.println("请选择棋谱：");
				for(int i = 0;i<as.size();i++) {
					System.out.println((i+1)+":"+as.get(i));
				}
				int choose = t.getInt(1,as.size());
				cd.old(as.get(choose-1));
				cd.show();
				break;
			case 4:
				System.exit(0);
				default:
					System.out.println("输入有误！");
			}
		}
	}
	public void start() throws IOException {
		while(true) {
			cd.show();
			if(cd.revoke()) {
				System.out.println((cd.isBlack==2?"黑子":"白子")+"是否悔棋？（y返回上一步,n下一個繼續），每人"+StaticTool.re+"悔棋机会");
				if(t.getBoolean("y","n")) {
					cd.reee();
					continue;
				}
				
			}
			System.out.println((cd.isBlack==1?"黑子":"白子")+"请落子");
			cd.downChess();
			if(cd.winwin()) {
				System.out.println((cd.isBlack==2?"黑子":"白子")+"获胜");
				System.out.println("是否存盘？y/n");
				if(t.getBoolean("y", "n")) {
					cd.save();
				}
				break;
			}
		}
	}
	
}
